<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="checkbox" name="" id="top" />
    <hr />
    <input type="checkbox" class="check" /><br />
    <input type="checkbox" class="check" /><br />
    <input type="checkbox" class="check" /><br />
    <input type="checkbox" class="check" /><br />
    <input type="checkbox" class="check" />
    <script>
      var input = document.querySelector('#top')
      var checks = document.querySelectorAll('.check')
      input.onclick = function () {
        // if (input.checked) {
        //   for (var i = 0; i < checks.length; i++) {
        //     checks[i].checked = true
        //   }
        // } else {
        //   for (var i = 0; i < checks.length; i++) {
        //     checks[i].checked = false
        //   }
        // }

        for (var i = 0; i < checks.length; i++) {
          checks[i].checked = input.checked
        }
      }
    </script>
  </body>
</html>
